import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      meta: { title: '首页 - 时尚货源平台' }
    },
    {
      path: '/merchants',
      name: 'merchants',
      component: () => import('../views/MerchantsView.vue'),
      meta: { title: '商家展示 - 时尚货源平台' }
    },
    {
      path: '/merchant/:id',
      name: 'merchant-detail',
      component: () => import('../views/MerchantDetailView.vue'),
      meta: { title: '商家详情 - 时尚货源平台' }
    },
    {
      path: '/contact',
      name: 'contact',
      component: () => import('../views/ContactView.vue'),
      meta: { title: '入驻联系 - 时尚货源平台' }
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
      meta: { title: '关于我们 - 时尚货源平台' }
    },
  ],
})

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title as string
  }
  next()
})

export default router
